package com.ruoyi.web.controller.lottery;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lottery.domain.LotAward;
import com.ruoyi.lottery.service.ILotAwardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖励Controller
 *
 * @author ruoyi
 * @date 2023-01-27
 */
@RestController
@RequestMapping("/lottery/award")
public class LotAwardController extends BaseController {

    @Autowired
    private ILotAwardService lotAwardService;

    /**
     * 查询奖励列表
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:list')")
    @GetMapping("/list")
    public TableDataInfo list(LotAward lotAward) {
        startPage();
        List<LotAward> list = lotAwardService.selectLotAwardList(lotAward);
        return getDataTable(list);
    }

    /**
     * 导出奖励列表
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:export')")
    @Log(title = "奖励", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LotAward lotAward) {
        List<LotAward> list = lotAwardService.selectLotAwardList(lotAward);
        ExcelUtil<LotAward> util = new ExcelUtil<LotAward>(LotAward.class);
        util.exportExcel(response, list, "奖励数据");
    }

    /**
     * 获取奖励详细信息
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lotAwardService.getById(id));
    }

    /**
     * 新增奖励
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:add')")
    @Log(title = "奖励", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LotAward lotAward) {
        return toAjax(lotAwardService.save(lotAward));
    }

    /**
     * 修改奖励
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:edit')")
    @Log(title = "奖励", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LotAward lotAward) {
        return toAjax(lotAwardService.updateById(lotAward));
    }

    /**
     * 删除奖励
     */
    @PreAuthorize("@ss.hasPermi('lottery:award:remove')")
    @Log(title = "奖励", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lotAwardService.removeBatchByIds(Arrays.asList(ids)));
    }
}
